import { Ajax } from '../utils/http';

export class ResearchCategoryService {
    public async send(): Promise<Array<ArticleCategory>> {
        let response: Array<ArticleCategory>;
        let data = {
            type: 1,
            pid: 2
        }
        try {
            response = await new Ajax<Array<ArticleCategory>>('/article/articleCategory', data).post();
        } catch (e) {
            throw e;
        }
        return response;
    }
}




export class ResearchLatestService {
    public async send(): Promise<ResearchData> {
        let response: ResearchData;
        let data = {
            type: 2,
            p: 1,
            psize: 3
        }
        try {
            response = await new Ajax<ResearchData>('/index/articleList', data).post();
        } catch (e) {
            throw e;
        }
        return response;
    }
}

export class ResearchService {
    private startdate: string;
    private enddate: string;
    private searchkey: string;
    private articletype: string;
    private page: number;
    constructor(_startdate: string, _enddate: string, _searchkey: string, _articletype: string, _page: number) {
        this.startdate = _startdate;
        this.enddate = _enddate;
        this.searchkey = _searchkey;
        this.articletype = _articletype;
        this.page = _page;
    }

    public async send(): Promise<ResearchData> {
        let response: ResearchData;
        let data = {
            startdate: this.startdate,
            enddate: this.enddate,
            searchkey: this.searchkey,
            articletype: this.articletype,
            p: this.page,
            psize: 12
        }
        try {
            response = await new Ajax<ResearchData>('/article/articleList', data).post();
        } catch (e) {
            throw e;
        }
        return response;
    }
}


export class ResearchCollectService {

    private page: number;
    constructor(_page: number) {
        this.page = _page;
    }

    public async send(): Promise<ResearchData> {
        let response: ResearchItem[];
        let data = {
            objecttype: 1,
            p: this.page,
            psize: 12
        }
        try {
            response = await new Ajax<ResearchItem[]>('/user/collectList', data).post();
        } catch (e) {
            throw e;
        }
        return { list: response, total: response.length };
    }
}


export interface ArticleCategory {
    id: string;
    name: string;
}


/*List*/
export interface ResearchItem {
    id: string;
    title: string;
    abstract: string;
    thumb: string;
    content: string;
    viewcount: string;
    collectcount: string;
    likecount: string;
    createtime: string;
    isfollow: number;
    islike: number;
}

/*Data*/
export interface ResearchData {
    list: ResearchItem[];
    total: number;
}

